/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon
 												
Class							:				PlayerExistsCondition
 
Function						: 				Provides a class for whether a player 
 												exists condition
****************************************************************************/
package planninglanguage.softconditions;

import base.WargusGameState;


public class PlayerDefeatedSoftCondition extends SoftCondition {

	int m_selfPlayerID;
	int m_opponentPlayerID;
	float m_selfStrength;
	float m_opponentStrength;
	
	public PlayerDefeatedSoftCondition(int a_selfPlayerID,int a_opponentPlayerID,float a_selfStrength,float a_opponentStrength)
	{
		m_selfPlayerID = a_selfPlayerID;
		m_opponentPlayerID = a_opponentPlayerID;
		m_selfStrength = a_selfStrength;
		m_opponentStrength = a_opponentStrength;
	}
	public String toString(int tabs)
	{
		String str= super.toString(tabs);
		int i;
		
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str +  "PlayerDefeatedSoftCondition( self = " + m_selfPlayerID + " (" + m_selfStrength + "), opponent = " + m_opponentPlayerID + " (" + m_opponentStrength +"))";		
		return str;
	}
	public float test(WargusGameState a_gameState)
	{
		float selfStrength = 0.0f;
		float opponentStrength = 0.0f;
		
		float initialRatio = 0.5f;
		float currentRatio = 0.5f;
		if (m_selfStrength>m_opponentStrength) initialRatio = 1.0f - 0.5f*(m_opponentStrength/m_selfStrength);		
		if (m_selfStrength<m_opponentStrength) initialRatio = 0.5f*(m_selfStrength/m_opponentStrength);					

		selfStrength = a_gameState.getPlayerStrength(m_selfPlayerID);
		opponentStrength = a_gameState.getPlayerStrength(m_opponentPlayerID);
		
		if (selfStrength>opponentStrength) currentRatio = 1.0f - 0.5f*(opponentStrength/selfStrength);		
		if (selfStrength<opponentStrength) currentRatio = 0.5f*(selfStrength/opponentStrength);	
		
		System.out.println("PlayerDefeatedSoftCondition( self = " + m_selfPlayerID + " (" + m_selfStrength + "), opponent = " + m_opponentPlayerID + " (" + m_opponentStrength +"))");
		System.out.println("initialRatio: " + initialRatio + " , currentRatio: " + currentRatio);
		
		if (initialRatio<currentRatio) {
			System.out.println("progress: " + (currentRatio-initialRatio)/(1.0f-initialRatio));
			return (currentRatio-initialRatio)/(1.0f-initialRatio);
		}
		
		System.out.println("progress: " + 0.0f);
		return 0.0f;
	}
	
}